package com.example.weather.ui

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.example.weather.R
import com.example.weather.adapter.AirQualityAdapter
import com.example.weather.base.BaseBindingFragment
import com.example.weather.databinding.FragmentAirQualityBinding
import com.example.weather.model.AirQualityItem

class AirQualityFragment : BaseBindingFragment<FragmentAirQualityBinding>() {

    override fun initBinding(
        inflater: LayoutInflater,
        parent: ViewGroup?
    ): FragmentAirQualityBinding {
        return FragmentAirQualityBinding.inflate(inflater, parent, false)
    }

    override fun initView() {
        setupRecyclerView()
    }

    private fun setupRecyclerView() {
        val airQualityItems = listOf(
            AirQualityItem(R.drawable.ic_real_feel, "体感温度", "33°"),
            AirQualityItem(R.drawable.ic_wind, "风速", "16公里/小时"),
            AirQualityItem(R.drawable.ic_rain_chance, "相对湿度", "59%"),
            AirQualityItem(R.drawable.ic_uv_index, "能见度", "30公里"),
            AirQualityItem(R.drawable.ic_so2, "大气压强", "1011hPa"),
            AirQualityItem(R.drawable.ic_o3, "云量", "91%")
        )

        val adapter = AirQualityAdapter(airQualityItems)
        binding.airQualityRecyclerView.layoutManager = GridLayoutManager(requireContext(), 3)
        binding.airQualityRecyclerView.adapter = adapter
        
        // 设置刷新按钮点击事件
        binding.refreshButton.setOnClickListener {
            // 刷新数据逻辑
            refreshData()
        }
    }

    private fun refreshData() {
        // 这里可以重新获取数据并更新适配器
        // adapter.notifyDataSetChanged()
    }
}